﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD.Shells
{
    public class Rocket : SquarePointSprite, IFixedGameUpdate
    {
        GameObject target;
        float dmg;
        long startTime;

        public Rocket(Vector3 pos, float dmg, GameObject target)
            : base(pos, .2f, new Vector4(1, 0, 0, 1), "Linear")
        {
            this.target = target;
            this.dmg = dmg;
            startTime = inGameTime;
        }

        public void FixedGameUpdate()
        {
            var dir = position - target.position;
            if (dir.Length() < 0.2f)
            {
                Explosion(dmg, 1.5f);
                UnRegister(this);
            }
            dir.Normalize();

            float toTarget = Math.Max(0, Math.Min((inGameTime - startTime) / 1000f - .2f, 1));
            float up = 1 - toTarget;

            Register(new RocketParticle(position, .2f));

            position -= (up * Vector3.Down + toTarget * dir) * (toTarget * (inGameTime - startTime)/3000f  + 1) * 0.02f;
        }
    }
}
